-- hp_to_absorb_damage
-- created by chendh
-- 生命低于一定百分比时降低所受的伤害

return {
    -- 返回的是降低的伤害值
    apply = function(prop, baseValue)
        return prop[3];
    end,

    trigger = function(who, prop, damage)
        local rate = math.modf(1000 * who:queryAttrib("hp") / who:queryAttrib("max_hp"));

        -- 降低加成
        local value = prop[3];
        local specialProp = PropM.combine(who, "prop_force_add", prop[1]);
        if specialProp[3] > 0 then
            value = PropM.apply(specialProp, value);
        end

        if (rate < tonumber(prop[2])) then
            return math.floor(damage * value / 1000);
        end

        return 0;
    end,

    record = function(target, prop, path)
        return false;
    end
};
